//
//  AppMacro.h
//  DriveSchoolCoach
//
//  Created by TangBin on 2019/7/4.
//  Copyright © 2019 TangBin. All rights reserved.
//

#ifndef AppMacro_h
#define AppMacro_h

// APP相关的宏定义

#define kCSKeyWindow [UIApplication sharedApplication].keyWindow

// 应用的版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]



// app 名称
#define kAppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]

// app build版本
#define kAppBuild [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]



///------ 获取当前语言 ------
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

#define kScreenW  [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScreenRect   [UIScreen mainScreen].bounds


#ifndef kSystemVersion
#define kSystemVersion [UIDevice systemVersion]
#endif

#ifndef kiOS6Later
#define kiOS6Later (kSystemVersion >= 6)
#endif

#ifndef kiOS7Later
#define kiOS7Later (kSystemVersion >= 7)
#endif

#ifndef kiOS8Later
#define kiOS8Later (kSystemVersion >= 8)
#endif

#ifndef kiOS9Later
#define kiOS9Later (kSystemVersion >= 9)
#endif

#ifndef kiPhone4
#define kiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

#ifndef kiPhone5
#define kiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

#ifndef kiPhone6
#define kiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

#ifndef kiPhone6Plus
#define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

#ifndef kiPhoneX
//#define kiPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define kiPhoneX (kScreenHeight >= 812?YES:NO)
#endif


#ifndef kiPod4
#define kiPod4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

#ifndef kiPod3
#define kiPod3 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(320, 480), [[UIScreen mainScreen] currentMode].size) : NO)
#endif

#ifndef STATUSBAR_HEIGHT
///< 状态条高度s
#define STATUSBAR_HEIGHT [UIApplication sharedApplication].statusBarFrame.size.height
#endif

// 标准系统状态栏高度
#define SYS_STATUSBAR_HEIGHT (20)

#ifndef IPHONEX_BOTTOM_SPACE
#define IPHONEX_BOTTOM_SPACE (kiPhoneX?34.0:0.0)
#endif

#define IPHONEX_TOP_SPACE (kiPhoneX?24.0:0.0)

// 不包含状态和topspace
#define NAVBAR_HEIGHT_NOTOPSPACE (44)

// 不包含状态栏的高度
#ifndef NAVBAR_HEIGHT_NOSTATUS
#define NAVBAR_HEIGHT_NOSTATUS (IPHONEX_TOP_SPACE + NAVBAR_HEIGHT_NOTOPSPACE)
#endif

// 包含状态栏的高度
#ifndef NAVBAR_HEIGHT_STATUS
#define NAVBAR_HEIGHT_STATUS (SYS_STATUSBAR_HEIGHT + NAVBAR_HEIGHT_NOSTATUS)
#endif


#ifndef TABBAR_HEIGHT
#define TABBAR_HEIGHT (kiPhoneX?IPHONEX_BOTTOM_SPACE+49.0 : 49.0)
#endif

// 热点栏高度
#define HOTSPOT_STATUSBAR_HEIGHT  (20)
// APP_STATUSBAR_HEIGHT=SYS_STATUSBAR_HEIGHT+[HOTSPOT_STATUSBAR_HEIGHT]
#define APP_STATUSBAR_HEIGHT  (CGRectGetHeight([UIApplication sharedApplication].statusBarFrame))

// 根据APP_STATUSBAR_HEIGHT判断是否存在热点栏
#define IS_HOTSPOT_CONNECTED     (APP_STATUSBAR_HEIGHT==(SYS_STATUSBAR_HEIGHT+HOTSPOT_STATUSBAR_HEIGHT)?YES:NO)


#define kAutoSizeScaleX [UIScreen mainScreen].bounds.size.width/375.
#define kAutoSizeScaleY [UIScreen mainScreen].bounds.size.height/667.

// iphone7p
#define SYRealValue(value) ((value)/414.0f*[UIScreen mainScreen].bounds.size.width)

///------ Ratio(Point)基于iPhone6 ------
#define kRatioX6 ([UIScreen mainScreen].bounds.size.width / 375.)
#define kRatioY6 (([UIScreen mainScreen].bounds.size.height) / 667.)

///------ Ratio(Point)基于iPhone5s ------
#define kRatioX5 ([UIScreen mainScreen].bounds.size.width / 320)
#define kRatioY5 ([UIScreen mainScreen].bounds.size.height / 568)

#define ISPAD         (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
/*----------------距离------------------------------------------------*/
// 以iPhone5为基准(UI妹纸给你的设计图是iPhone5的),当然你也可以改,但是出图是按照7P(6P)的图片出的,因为大图压缩还是清晰的,小图拉伸就不清晰了,所以只出一套最大的图片即可
// 计算比例
// X坐标
#define KLineX(l) l*kRatioX6
// Y坐标
#define KLineY(l) l*kRatioY6
// 字体
#define kFont(x) [UIFont systemFontOfSize:x*kRatioX6]

#define kFontCustSize(x) (x * kRatioX6)

// 十六进制颜色转成rgb
#define UIColorFromRGBA(RGBValue, alphaValue) [UIColor colorWithRed:((float)((RGBValue & 0xFF0000) >> 16))/255.0 green:((float)((RGBValue & 0x00FF00) >> 8))/255.0 blue:((float)(RGBValue & 0x0000FF))/255.0 alpha:alphaValue]


// PingFang-SC-Heavy字的大小
#define kFontPingFnagSCHeavy(s) [UIFont fontWithName:@"PingFang-SC-Heavy" size:s]

#pragma mark - 颜色

#define RGBCOLOR(R,G,B)  [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1]

#define kLineColor [UIColor colorWithHexString:@"#F1F1F1"]

// 白色
#define kWhiteColor [UIColor colorWithHexString:@"#FFFFFF"]

// 黑色
#define kBlackColor [UIColor colorWithHexString:@"#000000"]
// #DC0606
#define kRedColor [UIColor colorWithHexString:@"#DC0606"]

// 视图主色
#define kThemeViewBackgroundColor [UIColor colorWithHexString:@"#EFEFEF"]

// 视图控制器中的视图默认颜色
#define kMainBaseViewBackgroundColor [UIColor colorWithHexString:@"#f8f8f8"]

#define kThemeColor [UIColor colorWithHexString:@"#F6020A"]

// 一级标题颜色
#define kFirstLevelTitleColor [UIColor colorWithHexString:@"#333333"]

// 二级标题颜色
#define kSecondLevelTitleColor [UIColor colorWithHexString:@"#666666"]

// 三级标题颜色
#define kThirdLevelTitleColor [UIColor colorWithHexString:@"#999999"]

#pragma mark - TabBar 背景色 字的颜色
// TabBar 背景色
#define kTabBarBackgroundColor [UIColor colorWithHexString:@"#ffffff"]

// TabBar 标题的nor的颜色
#define kTabBarItemTitleNorColor [UIColor colorWithHexString:@"#333333"]

// TabBar 标题的sel的颜色
#define kTabBarItemTitleSelColor [UIColor colorWithHexString:@"#F6020A"]

#pragma mark - NavBar 背景色 字的颜色
// 背景色
#define kNavBarBackgroundColor [UIColor colorWithHexString:@"#FFFFFF"]

// 字的颜色
#define kNavBarTitleColor [UIColor colorWithHexString:@"#333333"]


#define kHeight(x) ((kScreenHeight/667)*x)
#define kWidth(x) ((kScreenWidth/375.0)*x)
/** 根据ip6的屏幕来拉伸 */
#define kRealValue(with) ((with) * W)
/** 设置字体号 */
#define FONT_Regular(a)  [UIFont fontWithName:@"PingFangSC-Regular" size:(a * W)]
#define FONT_Medium(a)   [UIFont fontWithName:@"PingFangSC-Medium" size:(a * W)]
#define FONT_Semibold(a) [UIFont fontWithName:@"PingFangSC-Semibold" size:(a * W)]
/* 防止参数为nil */
#define checkNil(y) ((y == nil)||[y isKindOfClass:[NSNull class]])?@"":y

#pragma mark - 字体大小

/*
 用法
  [UIFont systemFontOfSize:AdapationLabelFont(<#n#>)];
  [UIFont boldSystemFontOfSize:AdapationLabelFont(<#n#>)];
 */

#define IOS_VERSION_10_OR_LATER (([[[UIDevice currentDevice]systemVersion]floatValue]>=10.0)? (YES):(NO))

#define AdapationLabelFont(n) (IOS_VERSION_10_OR_LATER?((n-1)*([[UIScreen mainScreen]bounds].size.width/375.0f)):((n)*([[UIScreen mainScreen]bounds].size.width/375.0f)))

// MARK: -字的大小
#ifndef FONTSIZE
#define FONTNAMESIZE(name,font) [UIFont fontWithName:name size:font]
#define FONTSIZE(font) [UIFont systemFontOfSize:font]
#define FONTSIZE_9 FONTSIZE(9)
#define FONTSIZE_10 FONTSIZE(10)
#define FONTSIZE_11 FONTSIZE(11)
#define FONTSIZE_12 FONTSIZE(12)
#define FONTSIZE_13 FONTSIZE(13)
#define FONTSIZE_14 FONTSIZE(14)
#define FONTSIZE_15 FONTSIZE(15)
#define FONTSIZE_16 FONTSIZE(16)
#define FONTSIZE_17 FONTSIZE(17)
#define FONTSIZE_18 FONTSIZE(18)
#define FONTSIZE_19 FONTSIZE(19)
#define FONTSIZE_20 FONTSIZE(20)
#define FONTSIZE_21 FONTSIZE(21)
#define FONTSIZE_22 FONTSIZE(22)
#define FONTSIZE_23 FONTSIZE(23)

#endif

#ifndef FONTBOLDSIZE
#define FONTBOLDSIZE(font) [UIFont boldSystemFontOfSize:font]
#define FONTBOLDSIZE_9 FONTBOLDSIZE(9)
#define FONTBOLDSIZE_10 FONTBOLDSIZE(10)
#define FONTBOLDSIZE_11 FONTBOLDSIZE(11)
#define FONTBOLDSIZE_12 FONTBOLDSIZE(12)
#define FONTBOLDSIZE_13 FONTBOLDSIZE(13)
#define FONTBOLDSIZE_14 FONTBOLDSIZE(14)
#define FONTBOLDSIZE_15 FONTBOLDSIZE(15)
#define FONTBOLDSIZE_16 FONTBOLDSIZE(16)
#define FONTBOLDSIZE_17 FONTBOLDSIZE(17)
#define FONTBOLDSIZE_18 FONTBOLDSIZE(18)
#define FONTBOLDSIZE_19 FONTBOLDSIZE(19)
#define FONTBOLDSIZE_20 FONTBOLDSIZE(20)
#define FONTBOLDSIZE_21 FONTBOLDSIZE(21)
#define FONTBOLDSIZE_22 FONTBOLDSIZE(22)
#define FONTBOLDSIZE_23 FONTBOLDSIZE(23)
#endif

// TabBar 标题字的大小
#define kTabBarItemTitleFont FONTSIZE(kFontCustSize(10))

// NavBar 标题的大小
#define kNavBarTitleFont FONTSIZE(kFontCustSize(16))


// MARK: -打印日志
#pragma mark - 打印日志
#ifdef DEBUG
#define debugLog(...) NSLog(__VA_ARGS__)
#define debugMethod() NSLog(@"%s--line:%d", __func__, __LINE__)
#define debugLogFrame(frame) NSLog(@"frame[X=%.2f, Y=%.2f, W=%.2f, H=%.2f]", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)
#define debugLogSize(size) NSLog(@"size[W=%.2f, H=%.2f]", size.width, size.height)
#define debugLogPoint(point) NSLog(@"point[X=%.2f, Y=%.2f]", point.x, point.y)

#define debugLogFrameName(name, frame) NSLog(@"%@-frame[X=%.2f, Y=%.2f, W=%.2f, H=%.2f]", name, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)
#define debugLogSizeName(name, size) NSLog(@"%@-size[W=%.2f, H=%.2f]", name, size.width, size.height)
#define debugLogPointName(name, point) NSLog(@"%@-point[X=%.2f, Y=%.2f]", name, point.x, point.y)
#else
#define debugLog(...)
#define debugMethod()
#define debugLogFrame(frame)
#define debugLogSize(size)
#define debugLogPoint(point)

#define debugLogFrameName(name, frame)
#define debugLogSizeName(name, size)
#define debugLogPointName(name, point)
#endif

#endif /* AppMacro_h */
